/**   
 * Copyright © 2016 国网信通亿力科技有限责任公司. All rights reserved.
 * 
 * @Title: BaseContextListener.java 
 * @Prject: com.ylkj.path.common
 * @Package: com.ylkj.path.common.listener 
 * @Description: TODO
 * @author: zhm   
 * @date: 2016-10-28 下午2:07:11 
 * @version: V1.0   
 */
package com.janmu.zzlstore.start;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/** 
 * @ClassName: WebSysContextListener 
 * @Description: web工程启动系统参数设置类
 * @author: zhm
 * @date: 2016-10-28 下午2:07:11  
 */
public class WebSysContextListener implements ServletContextListener {
     
    /**
     * @fieldName: serverInfo
     * @fieldType: String
     * @Description: web服务器的版本信息
     */
    private String serverInfo;
    
    @Override
    public void contextInitialized(ServletContextEvent event) {
    	serverInfo = event.getServletContext().getServerInfo();// web服务器类型（tomcat or Weblogic）
		if (null != serverInfo && !"".equals(serverInfo)) {
			System.setProperty("WEB.SERVER.INFO", serverInfo);
		} else {
			event.getServletContext().log("无法获取系统部署的web服务器信息！");
		}
		String realPath = event.getServletContext().getRealPath("/");
		String path = realPath == null ? System.getProperty("WEB.SYS.PATH") : realPath;// 项目部署的绝对路径
		if (null != path && !"".equals(path)) {
			if (serverInfo.indexOf("WebLogic") > -1) {
				path = path + File.separator;
			}
			event.getServletContext().log("系统参数变量WEB.SYS.PATH,值为：" + path);
			System.setProperty("WEB.SYS.PATH", path);
		} else {
			event.getServletContext().log("系统参数配置文件路径设置失败，请手工设置启动参数 -DAPP.CONFIG.PATH = 系统部署路径：APP.CONFIG.PATH！");
			System.exit(-1);
		}
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        
    }
    
}
